package com.milhouz.findmydroid;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ListView;

import com.milhouz.findmydroid.bean.Game;
import com.milhouz.findmydroid.view.MenuItem;
import com.milhouz.findmydroid.view.MenuItem.MenuType;
import com.milhouz.findmydroid.view.MenuItemAdapter;

public class MainMenuActivity extends Activity {

	private ListView mMenuList;
	private MenuItemAdapter mAdapter;

	@Override
	public void onBackPressed() {
		// Exit Application
		moveTaskToBack(true);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		// Set the fullscreen mode
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.main);

		final Game game = new Game();

		MenuItem[] items = new MenuItem[6];
		items[0] = new MenuItem(MenuType.TEAMS);
		items[1] = new MenuItem(MenuType.TIME);
		items[2] = new MenuItem(MenuType.NB_CARDS);
		items[3] = new MenuItem(MenuType.USE_CUSTOM);
		items[4] = new MenuItem(MenuType.CUSTOM);
		items[5] = new MenuItem(MenuType.RULES);

		// set up image view
		mMenuList = (ListView) this.findViewById(R.id.menuItemList);
		mAdapter = new MenuItemAdapter(this, game, items);
		mMenuList.setAdapter(this.mAdapter);

		mAdapter.updateItems(items);

		Button play = (Button) this.findViewById(R.id.playButton);
		play.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				Intent intent = new Intent(getApplicationContext(), FindMyDroidGameActivity.class);
				intent.putExtra(getString(R.string.intent_extra_game), game);
				if (intent != null) {
					startActivity(intent);
				}
			}
		});

	}

	@Override
	protected void onResume() {
		super.onResume();
	}
}
